package com.ruoyi.controller.jpjs.building;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.SysParameterService;
import com.ruoyi.service.jpjs.param.ParamService;
import com.ruoyi.service.jpjs.person.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/building")
public class BuildingController extends BaseController {

    private String prefix = "jpjs/building";

    @Autowired
    private SysParameterService sysParameterService;

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String building() {
        return prefix + "/Building";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo findBuilding() {
        startPage();
        List<Map<String, Object>> list = sysParameterService.findNameByType("楼号");
        return getDataTable(list);
    }

    @GetMapping("/add")
    public String addBuilding() {
        return prefix + "/add";
    }

    @PostMapping("/save")
    @ResponseBody
    public AjaxResult save(@RequestParam Map<String, Object> map) {
        return toAjax(sysParameterService.save(map));
    }

    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(sysParameterService.remove(ids));
    }

    @PostMapping("/checkNameUnique")
    @ResponseBody
    public int checkNameUnique(@RequestParam Map<String, Object> map) {
        return sysParameterService.checkNameUnique(map);
    }

    @GetMapping("/edit/{id}")
    public String editPerson(@PathVariable("id") String id, ModelMap mmp) {
        mmp.put("building", sysParameterService.findParameter(id));
        return prefix + "/edit";
    }
}
